const _Comment = require('../models/comment');
var moment = require('moment');

exports.comment= function(req, res) {
    var goods_id = req.body.comment.goods_id;
    var from = req.body.comment.from;
    var context = req.body.comment.context;
    var time = moment(Date.now()).format("YYYY-MM-DD HH:mm:ss");

    var _comment = {goods_id,from,context,time};
    var comment = new _Comment(_comment);

    comment.save(function(err,comment){
        if(err){
            console.log(err)
        }
        if(comment){
            return res.send("发表成功")
        }
    })
};

//删除评论
exports.DelCom = function(req,res){
    var comment = req.body.comment
    _Comment.remove({_id:comment._id},function(err,result){
        if(err){
            return console.log(err);
        }
        if(result){
            return res.send("删除成功");
        }
    })
}